package com.company.section3;

/**
 * @author cbf4Life cbf4life@126.com
 * I'm glad to share my knowledge with you all.
 * 业务场景模拟类
 */
public class Client {
	
	public static void main(String[] args) {
		//产生三毛这个狙击手
		Snipper sanMao = new Snipper();
		/*向下转型失败，编译不出错。但是运行的时候出错。向下转型的时候，父类没有
		sanMao.setRifle((AUG)(new Rifle()));
		sanMao.killEnemy();*/

		sanMao.setRifle((new AUG()));
		sanMao.killEnemy();

	}
}

class Parent {
	public void draw(){}
}
class ChildA extends Parent {
	public void draw(){System.out.println("pring ChildA");}
}
class ChildB extends Parent {
	public void draw(){System.out.println("pring ChildB");}
}
class Test
{
	public static void testInstanceof(Object x)
	{
		System.out.println("x instanceof Parent:  "+(x instanceof Parent));
		System.out.println("x instanceof ChildA:  "+(x instanceof ChildA));
		System.out.println("x getClass Parent:  "+(x.getClass() == Parent.class));
		System.out.println("x getClass ChildA:  "+(x.getClass() == ChildA.class));
	}
	public static void main(String[] args) {
		testInstanceof(new Parent());
		System.out.println("---------------------------");
		testInstanceof(new ChildA());
		System.out.println("---------------------------");
		testInstanceof(new ChildB());
	}
}

